package com.ls.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ls.controller.loginrecord.model.QueryLoginRecordModel;
import com.ls.entity.Customer;
import com.ls.entity.LoginRecord;
import com.ls.entity.SysUser;
import com.ls.mapper.LoginRecordMapper;
import com.ls.service.ILoginRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ls.utils.ResultData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户登录记录表，管理员和C端用户都放在这个表里面 服务实现类
 * </p>
 *
 * @author pengyu
 * @since 2024-10-01
 */
@Service
public class LoginRecordServiceImpl extends ServiceImpl<LoginRecordMapper, LoginRecord> implements ILoginRecordService {

    /** 查询登录记录 */
    @Override
    public ResultData getPaging(QueryLoginRecordModel model) {
        String entityName = model.getEntityName();
        Long entityId = model.getEntityId();
        Page page = new Page(model.getPageNum(), model.getPageSize());
        IPage<LoginRecord> dtoIPage = this.getBaseMapper().selectPage(page,
                new LambdaQueryWrapper<LoginRecord>()
                        .eq(StringUtils.isNotBlank(entityName), LoginRecord::getEntityName, entityName)
                        .eq(entityId!=null, LoginRecord::getEntityId, entityId)
                        .orderByDesc(LoginRecord::getRecordId)
        );
        return ResultData.successData(dtoIPage);
    }
}
